package webapputilities;

import java.io.IOException;
import javax.servlet.http.*;
import utilities.MailUtilities;


@SuppressWarnings("serial")
public class SendMail extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		resp.setContentType("text/plain");
		
		boolean returnStatus = true;
		String fromName, fromAddress, toName, toAddress, subject, messageBody;
		
		fromName = fromAddress = toName = toAddress = subject = messageBody = null;
		fromName = req.getParameter(Constants.FROM_NAME);
		fromAddress = req.getParameter(Constants.FROM_ADDRESS);
		toName = req.getParameter(Constants.TO_NAME);
		toAddress = req.getParameter(Constants.TO_ADDRESS);
		subject = req.getParameter(Constants.MAIL_SUBJECT);
		messageBody = req.getParameter(Constants.MAIL_MESSAGE_BODY);
		
		//System.out.println("from: "+fromName+"fromAddress: "+fromAddress+" toName: "+toName+" toAddress: "+toAddress+" Subject: "+subject+" messageBody: "+messageBody+" ");
		returnStatus = MailUtilities.sendMail(fromName, fromAddress, toName, toAddress, subject, messageBody);
		
		if (returnStatus) {
			resp.getWriter().println("Successfully sent the Email");
		} else {
			resp.getWriter().println("Error sending the Email");
		}
	}
}
